/* 
 * File:   main.cpp
 * Author: max
 *
 * Created on October 19, 2012, 9:29 PM
 */

#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include "client_Cliente.h"
#include "common_ClientConfFileManager.h"

using namespace std;
using namespace TP;
using namespace TP::Comunicacion;

#define SUCCESS_EXIT 0
#define CONNECTION_FAILED 1
#define INVALID_SERVICE_REFERENCE 2
#define INVALID_ARGS 3

int main(int argc, char** argv) {
    
    
    int val = SUCCESS_EXIT;
    
    try
    {
        // Verifico la cantidad de parametros de la aplicacion.
        if (argc != 2)
            throw INVALID_ARGS;

        ClientConfFileManager config ("client.config.xml");
        Cliente cliente (&config, cerr);
        cliente.Iniciar();

        // Atiendo a los eventos provenientes de entrada estandar.
        //
        string comando = "";
        cout << "Salir (q): ";
                
        while (std::getline(cin, comando, '\n'))
        {
            if ("q" == comando)
                break;
            else
                cout << endl << "Comando invalido..." << endl << endl << "Salir (q): ";
        }        
        
        cliente.Finalizar();
        
    }
    catch (Excepcion& pEx)
    {
        cerr << pEx.what() << endl;
        val = CONNECTION_FAILED;
    }
    catch (int pEx)
    {
        val = pEx;
    }

    return val;
}

